package com.bthdung.studios.lesson12.glUtil;

import java.io.InputStream;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public final class AndUtil
{
	public static String readTextResource(Context context, int rawId)
	{
		String text = "";

		try
		{
			InputStream in = context.getResources().openRawResource(rawId);
			FInputStreamReader reader = new FInputStreamReader(in);
			text = reader.readToEnd();

			reader.close();
		}
		catch (Exception e)
		{

		}

		return text;
	}

	public static Bitmap loadBitmap(Context context, int resourceID, boolean enableScale)
	{
		BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inScaled = enableScale;

		Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceID, opt);

		return bitmap;
	}

	public static float clamp(float value, float min, float max)
	{
		if (value < min) return min;
		else if (value > max) return max;
		else
			return value;
	}
}
